package af.Action;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

import af.Class.Factor;
import af.Form.FactorForm;


public class FactorAction extends DispatchAction{

	public ActionForward ListaFactores(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
		Factor fct = new Factor();
        //HttpSession session = request.getSession();

        //traigo el listado de todos los Factores
        request.getSession().setAttribute("grFactor", fct.ListaFactor());
        

        return mapping.findForward("listar");
    }

	public ActionForward NuevoFactor(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
		//obtengo el formulario
		FactorForm frm = (FactorForm) form;
		//seteo que el factor es nuevo
		frm.setNuevo("S");
		return mapping.findForward("nuevo");
	}
	public ActionForward ModificarFactor(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
		   //recibo el codigo del Factor
			String cod = request.getParameter("codigo");
			//creo un nuevo factor
			Factor fct = new Factor();
			//tomo el formulario
			FactorForm frm = (FactorForm) form;
			//estipulo que no es nuevo si no que una modificacion
			frm.setNuevo("M");
			//seteo el codigo
			frm.setCodigo(cod);
			//traigo los datos del Factor para mostrarlos en la vista
			frm = fct.TraeFactor(frm);
						
		return mapping.findForward("modificar");
	}
	
	public ActionForward EliminarFactorForm(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
			//traigo el codigo
			String cod = request.getParameter("codigo");
			
			Factor fct = new Factor();
			//traigo el fromulario
			FactorForm frm = (FactorForm) form;
			//seteo el codigo de la ubicacion a eliminar
			frm.setCodigo(cod);
			//elimino la Ubicacion
			fct.EliminaFactor(frm);
				
						
			return mapping.findForward("eliminar");
	}
	
}



